package com.jeesite.modules.mo.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.ic.entity.IcUser;
import com.jeesite.modules.ic.service.IcUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.mo.entity.MoRefund;
import com.jeesite.modules.mo.service.MoRefundService;

/**
 * 退款Controller
 * @author 李寒冰
 * @version 2025-02-18
 */
@Controller
@RequestMapping(value = "${adminPath}/mo/moRefund")
public class MoRefundController extends BaseController {

	@Autowired
	private MoRefundService moRefundService;
    @Autowired
    private IcUserService icUserService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public MoRefund get(String id, boolean isNewRecord) {
		return moRefundService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("mo:moRefund:view")
	@RequestMapping(value = {"list", ""})
	public String list(MoRefund moRefund, Model model) {
		model.addAttribute("moRefund", moRefund);
		return "modules/mo/moRefundList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("mo:moRefund:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<MoRefund> listData(MoRefund moRefund, HttpServletRequest request, HttpServletResponse response) {
		moRefund.setPage(new Page<>(request, response));
		Page<MoRefund> page = moRefundService.findPage(moRefund);
		for (MoRefund moRefund1 : page.getList()) {
			String userId = moRefund1.getUserId();
			IcUser icUser = icUserService.get(userId);
			moRefund1.setIcUser(icUser);
		}
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("mo:moRefund:view")
	@RequestMapping(value = "form")
	public String form(MoRefund moRefund, Model model) {
		model.addAttribute("moRefund", moRefund);
		return "modules/mo/moRefundForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("mo:moRefund:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated MoRefund moRefund) {
		moRefundService.save(moRefund);
		return renderResult(Global.TRUE, text("保存退款成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("mo:moRefund:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(MoRefund moRefund) {
		moRefundService.delete(moRefund);
		return renderResult(Global.TRUE, text("删除退款成功！"));
	}
	
}